const NAMES: Array<string> = [
    '断笔画墨',
    '默然相爱',
    '旅人不扰',
    '多余温情',
    '云中谁忆',
    '残雪冰心',
    '末世岛屿',
    '桑榆非晚',
    '扉匣与桔',
    '木槿暖夏',
    '空城旧梦',
];

function color16() {//十六进制颜色随机
    const r = Math.floor(Math.random() * 256);
    const g = Math.floor(Math.random() * 256);
    const b = Math.floor(Math.random() * 256);
    // const color = '#' + r.toString(16) + g.toString(16) + b.toString(16);
    const color = '#' + (Array(6).join('0') + (r.toString(16) + g.toString(16) + b.toString(16))).slice(-6);
    return color;
}

/**
 * 随机的中文名
 */
export function randomChineseName(): string {
    return NAMES[~~(NAMES.length * Math.random())];
}

/**
 * 随机颜色
 */
export function randomColor(): string {
    return color16();
}

/**
 * 两点距离
 * @param x1
 * @param y1
 * @param x2
 * @param y2
 */
export function distance(x1: number, y1: number, x2: number, y2: number): number {
    let dx = Math.abs(x1 - x2);
    let dy = Math.abs(y1 - y2);
    return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
}

/**
 * 简单碰撞检测
 * @param x1
 * @param y1
 * @param x2
 * @param y2
 * @param distance
 */
export function simpleCollisionDetection(x1: number, y1: number, x2: number, y2: number, distance: number): boolean {
    let dx = Math.abs(x1 - x2);
    let dy = Math.abs(y1 - y2);
    if (dx > distance || dy > distance) {
        return false;
    }
    // console.log(x1, x2, y1, y2, distance, '-', dx, dy);
    return Math.pow(distance, 2) > (Math.pow(dx, 2) + Math.pow(dy, 2));
}